<!--  -->
<template>
  <div class="container">
    <div class="mixins-demo">
      <h2>Vue Mixins 使用示例</h2>
      
      <!-- 基础混入示例 -->
      <div class="demo-section">
        <h3>1. 基础混入 (Data & Methods)</h3>
        <p class="description">展示混入基本数据和方法的用法</p>
        <div class="demo-content">
          <p>当前计数: <span class="highlight">{{ count }}</span></p>
          <div class="button-group">
            <button @click="increment">增加</button>
            <button @click="decrement">减少</button>
          </div>
        </div>
      </div>

      <!-- 生命周期混入示例 -->
      <div class="demo-section">
        <h3>2. 生命周期混入</h3>
        <p class="description">展示混入的生命周期钩子如何工作</p>
        <div class="demo-content">
          <p>组件创建时间: <span class="highlight">{{ createdTime }}</span></p>
          <p>最后更新时间: <span class="highlight">{{ lastUpdateTime }}</span></p>
          <div class="code-hint">
            <p>查看控制台输出顺序：</p>
            <code>1. Mixin created hook called</code>
            <code>2. Component created hook called</code>
          </div>
        </div>
      </div>

      <!-- 计算属性混入示例 -->
      <div class="demo-section">
        <h3>3. 计算属性混入</h3>
        <p class="description">展示混入的计算属性与组件本地计算属性的合并</p>
        <div class="demo-content">
          <div class="input-group">
            <input v-model="firstName" placeholder="输入名">
            <input v-model="lastName" placeholder="输入姓">
          </div>
          <p>完整姓名: <span class="highlight">{{ fullName }}</span></p>
          <p>反转姓名: <span class="highlight">{{ reverseName }}</span></p>
        </div>
      </div>

      <!-- Watch属性混入示例 -->
      <div class="demo-section">
        <h3>4. Watch属性混入</h3>
        <p class="description">展示混入的侦听器功能</p>
        <div class="demo-content">
          <input v-model="watchValue" placeholder="输入内容以触发watch">
          <p>变更历史:</p>
          <ul class="history-list">
            <li v-for="(item, index) in watchHistory" :key="index">
              {{ item }}
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import myMixins from './myMixins';

export default {
  name: 'MixinsDemo',
  mixins: [myMixins],
  
  data() {
    return {
      firstName: '',
      lastName: '',
      watchValue: '',
      watchHistory: []
    };
  },

  computed: {
    fullName() {
      return `${this.lastName}${this.firstName}`;
    }
  },

  created() {
    console.log('Component created hook called');
  }
};
</script>

<style scoped>
.container {
  padding: 20px;
  max-width: 800px;
  margin: 0 auto;
}

.mixins-demo h2 {
  color: #2c3e50;
  border-bottom: 2px solid #1976d2;
  padding-bottom: 10px;
  margin-bottom: 30px;
}

.demo-section {
  background: #fff;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.demo-section h3 {
  color: #1976d2;
  margin: 0 0 10px 0;
}

.description {
  color: #666;
  font-style: italic;
  margin-bottom: 20px;
  border-left: 3px solid #1976d2;
  padding-left: 10px;
}

.demo-content {
  background: #f8f9fa;
  padding: 15px;
  border-radius: 4px;
}

.highlight {
  color: #1976d2;
  font-weight: bold;
}

.button-group {
  margin-top: 10px;
}

button {
  background: #1976d2;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  margin-right: 10px;
  cursor: pointer;
  transition: background 0.3s;
}

button:hover {
  background: #1565c0;
}

.input-group {
  margin-bottom: 15px;
}

input {
  padding: 8px;
  margin-right: 10px;
  border: 1px solid #ddd;
  border-radius: 4px;
  width: 150px;
}

.code-hint {
  margin-top: 15px;
  padding: 10px;
  background: #f1f1f1;
  border-radius: 4px;
}

.code-hint code {
  display: block;
  color: #e83e8c;
  margin: 5px 0;
  font-family: monospace;
}

.history-list {
  list-style: none;
  padding: 0;
  margin: 10px 0;
  max-height: 150px;
  overflow-y: auto;
}

.history-list li {
  padding: 5px 10px;
  background: #fff;
  margin: 5px 0;
  border-radius: 4px;
  border: 1px solid #ddd;
}
</style>